package reversePrefix;

public class Solution {
    public String reversePrefix(String word, char ch) {
        for (int i = 0; i < word.length(); i++) {
            if(word.charAt(i) == ch) {
                return rev(word.substring(0,i+1))+word.substring(i+1,word.length());
            }
        }
        return word;
    }
    private String rev(String s) {
        char[] chars = s.toCharArray();
        int i =0,j = s.length()-1;
        while (i<j){
            char c = chars[i];
            chars[i++] = chars[j];
            chars[j--] = c;
        }
        return new String(chars);
    }
}
